<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>图形组合</title>
    <script type="text/javascript">
        function load () {
            let c = document.getElementById('myCanvas');
            let context = c.getContext('2d');
        
            let img = new Image();
            img.onload = function () {
                // 正常绘制
                // context.drawImage(img, 100, 100);
                // 压缩后的宽高为300, 212
                // context.drawImage(img, 100, 100, 300, 212);
                // 只想绘制一部分图片 前四个参数(从哪里开始，宽高多少开始截取)是截图的参数，后面的是怎么画的
                context.drawImage(img, 142, 100, 200, 200, 100, 100, 300, 212);
            }
            img.src = 'src/bg.jpg';
        }

        window.onload  = function () {
            load();
        }
    </script>
</head>
<body>
    <canvas id="myCanvas" style="border: 1px solid #000000" width="800" height="450">
        你的浏览器不支持canvas元素！
    </canvas>
</body>
</html>